#include "IceSpikes.h"


IceSpikes::IceSpikes(GameState *gameState, const b2Vec2 &size):
				PhysicalObject(gameState)
{
	addProperty("IceSpikes");
	addProperty("enemy");
	setLayer(3);

	m_texture = gameState->getTextureManager().getTexture("spikes.png");

	setSize(size);
	getBodyDef()->type = b2_staticBody;
	b2FixtureDef *fixDef = new b2FixtureDef;
	b2PolygonShape *shape = new b2PolygonShape;
	shape->SetAsBox(m_size.x*0.8f, m_size.y/2.0f, b2Vec2(0.0f,-m_size.y/2.0f),0);
	fixDef->shape = shape;
	fixDef->density = 2.0f;
	fixDef->restitution = 0.0f;
	fixDef->friction = 0;
	addFixtureDef(fixDef);
	setRotation(0.0f);
}


IceSpikes::~IceSpikes()
{
}


void IceSpikes::draw(){

	//drawFixtures();

	b2Vec2 pos = getPosition();
	
	glPushMatrix();
	{
		
		glTranslatef(pos.x, pos.y, 0); 
		glScalef(m_size.x*2, m_size.y*2, 1);
		glRotatef(m_body->GetAngle()*57.2957795f, 0.0f, 0.0f, 1.0f);

		sf::Texture::bind(m_texture); 

		glBegin(GL_QUADS);
		{
			glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 0.5f, -0.2f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.5f, 0.5f, -0.2f);
		}
		glEnd();
	}
	glPopMatrix();

	sf::Texture::bind(NULL);
}